package com.youhong.teethcare;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.youhong.teethcare.adapter.MyImageLoad;
import com.youhong.teethcare.services.Common;
import com.youhong.teethcare.settingpage.DeviceManagerActivity;
import com.youhong.teethcare.utils.AppManager;
import com.youth.banner.Banner;
import com.youth.banner.listener.OnBannerListener;

import java.util.ArrayList;
import java.util.List;

public class BannerActivity extends Activity implements ViewPager.OnPageChangeListener {

    TextView tv_skip;
    Banner banner;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AppManager.getInstance().addActivity(this);

        setContentView(R.layout.activity_banner);
        banner = findViewById(R.id.banner_banner);
        banner.setImageLoader(new MyImageLoad());
        //设置图片集合
        List<Integer> imageIds = new ArrayList<>();
        banner.stopAutoPlay();
        imageIds.add(R.mipmap.banner_1);
        imageIds.add(R.mipmap.banner_2);
        imageIds.add(R.mipmap.banner_3);
        imageIds.add(R.mipmap.banner_4);
        imageIds.add(R.mipmap.banner_5);
        imageIds.add(R.mipmap.banner_6);
        banner.setImages(imageIds);
        //banner设置方法全部调用完毕时最后调用
        banner.setDelayTime(3000);
        banner.start();
        banner.setOnPageChangeListener(this);
        tv_skip = findViewById(R.id.banner_tv_skip);
        tv_skip.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
                startActivity(intent);
            }
        });
        Common.userInfo.setFirstTimeIntoAPP(true);
    }

    boolean isStartActivity = false;
    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
/*
        Log.e("abc", "position:" + position + " ,PositionOffset:"
                + positionOffset + ",PositionOffsetPixel:" + positionOffsetPixels);
*/
        if (position == 5 && positionOffset > 0 && !isStartActivity) {
            isStartActivity = true;
            Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
            startActivity(intent);
        }
    }

    @Override
    public void onPageSelected(int position) {
        //当页面自动轮播到最后一幅图片的时候停止自动轮播
        if (position == 6) {

        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {



    }
}
